package com.hqx.exception;

public class FinallyTest {

    public static void main(String[] args) {
        try {
            System.out.println(getData());
        } catch (MyException e) {
            e.printStackTrace();
        }
//        System.out.println(test());
    }

    public static int getData() throws MyException{
        int data = 0;
        try {
            return data;
        }finally {
            System.out.println("如果try代码块中有return，finally代码块代码执行完毕才轮到return");
            data = 2;
        }
    }

    public static int test(){
        int ret = 0;
        try{
            int a = 5/0;
            return ret;
        }finally{
//            return 2;
            throw new RuntimeException("hello");
        }
    }
}
